import { newRule } from "@/utils/index";
import { FormOption } from "@/components/SuperForm/formType";
import { spinList, hasDirectionList, edgeTypeList, lineModeList } from "@/enums/MenuTypeEnum";
// import { useDictionaryStore } from "@/store/modules/dictionary";
// import { getPathGroup } from "@/api/map/index";
// import { MapNode, UpdateEdge } from "@/api/map/types";

interface params {
  mapId: number;
  data?: object;
}

// 表单提交模型类
export class NodeFormData {
  #formData: any = {
    mapId: -1,
    nodeId: -1,
    id: "",
    preNodeId: null,
    nodeNameCn: "",
    nodeNameEn: "",
    mapNodeType: -1,
    hasDirection: -1,
    shape: "",
    angle: 0,
    x: 0,
    y: 0,
    agvIds: [],
    deviceId: null,
    temp_edge_id: -1,
    temp_edge_name: "",
    obstacleNode: null,
    released: "",
    rotateType: 0,
    seriesId: "",
    modelsId: "",
    priorityNode: 0
  };

  #formOption: FormOption = {
    formItems: [
      // {
      //   field: "nodeId",
      //   prop: "nodeId",
      //   type: "number",
      //   label: "服务端ID",
      //   colSpan: 24,
      //   maxlength: 24,
      //   disabled: true,
      // },
      {
        field: "nodeNameEn",
        prop: "nodeNameEn",
        disabled: true,
        type: "input",
        label: "节点ID",
        colSpan: 24,
        maxlength: 24,
      },
      {
        field: "nodeNameCn",
        prop: "nodeNameCn",
        type: "input",
        label: "节点名称",
        placeholder: "请输入节点名称",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "mapNodeType",
        prop: "mapNodeType",
        type: "select",
        label: "节点类型",
        // options: mapNodeType,
        placeholder: "请选择节点类型",
        colSpan: 24,
      },
      {
        field: "hasDirection",
        prop: "hasDirection",
        type: "select",
        options: hasDirectionList,
        label: "是否设置方向",
        placeholder: "请选择设置方向",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "tempEdgeName",
        prop: "tempEdgeName",
        type: "input",
        label: "所属边",
        disabled: true,
        placeholder: "无",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "x",
        prop: "x",
        type: "number",
        label: "节点x(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "y",
        prop: "y",
        type: "number",
        label: "节点y(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "angle",
        prop: "angle",
        type: "number",
        label: "方向角度",
        isHidden: true,
        colSpan: 24,
        maxlength: 10,
      },
      // {
      //   field: "productName",
      //   prop: "productName",
      //   type: "input",
      //   label: "设备类型",
      //   placeholder: "请输入设备类型",
      //   isHidden: true,
      //   disabled: true,
      //   colSpan: 24,
      //   maxlength: 10,
      //   mapNodeType: [5, 6, 1, 3, 4],
      // },
      // {
      //   field: "deviceId",
      //   prop: "deviceId",
      //   type: "select",
      //   label: "关联设备",
      //   placeholder: "请选择关联设备",
      //   isHidden: true,
      //   colSpan: 24,
      //   maxlength: 10,
      //   options: [],
      //   mapNodeType: [5, 6, 1, 3, 4],
      // },
      // {
      //   field: "agvIds",
      //   prop: "agvIds",
      //   type: "select",
      //   label: "机器人设备",
      //   placeholder: "请选择机器人设备",
      //   isHidden: true,
      //   multiple: true,
      //   colSpan: 24,
      //   maxlength: 10,
      //   options: [],
      //   mapNodeType: [2],
      // },
      // {
      //   field: "preNodeId",
      //   prop: "preNodeId",
      //   type: "select",
      //   label: "关联充电前置点",
      //   placeholder: "请选择关联充电前置点",
      //   isHidden: true,
      //   colSpan: 24,
      //   options: [],
      //   mapNodeType: [1],
      // },
      // {
      //   field: "obstacleNode",
      //   prop: "obstacleNode",
      //   type: "select",
      //   options: hasDirectionList,
      //   label: "是否避障点",
      //   placeholder: "请选择是否避障点",
      //   colSpan: 24,
      //   maxlength: 10,
      // },
      // {
      //   field: "release",
      //   prop: "release",
      //   label: "状态",
      //   isHidden: true,
      //   slotName: "release",
      //   placeholder: "",
      //   colSpan: 24,
      //   maxlength: 10,
      // },
      // {
      //   field: "rotateType",
      //   prop: "rotateType",
      //   type: "select",
      //   options: spinList,
      //   label: "开/关同步旋转",
      //   placeholder: "请选择选择",
      //   colSpan: 24,
      //   maxlength: 10,
      //   isHidden: true,
      //   mapNodeType: [3, 4, 5, 6, 8],
      // },
      // {
      //   field: "seriesId",
      //   prop: "seriesId",
      //   multiple: true,
      //   type: "select",
      //   options: [],
      //   label: "机器人系列",
      //   placeholder: "请选择选择系列",
      //   colSpan: 24,
      //   isHidden: true,
      //   rotateType: [1, 2]
      // },
      // {
      //   field: "modelsId",
      //   prop: "modelsId",
      //   multiple: true,
      //   type: "select",
      //   options: [],
      //   label: "机器人型号",
      //   placeholder: "请选择选择型号",
      //   colSpan: 24,
      //   isHidden: true,
      //   rotateType: [1, 2]
      // },
      // {
      //   field: "priorityNode",
      //   prop: "priorityNode",
      //   type: "number",
      //   label: "停靠点优先级",
      //   placeholder: "请输入停靠点优先级",
      //   max: "99999",
      //   min: "0",
      //   step: "1",
      //   isHidden: true,
      //   colSpan: 24,
      //   maxlength: 6,
      //   mapNodeType: [2],
      // },
    ],
    labelWidth: "120px", //标签的长度
  };

  #formRules = {
    nodeNameEn: [newRule(true, "请输入节点ID", "blur")],
    nodeNameCn: [
      newRule(true, "请输入节点名称", "blur"),
      // {
      //   pattern: /^(?=.*[a-zA-Z])(?=.*\d).+$/,
      //   message: "请输入数字和英文字母组成，并且同时含有数字和英文字母",
      //   trigger: "blur",
      // },
    ],
    mapNodeType: [newRule(true, "请选择节点类型", "change")],
    hasDirection: [newRule(true, "请选择设置方向", "change")],
    shape: [newRule(true, "所属边", "blur")],
    angle: [
      {
        pattern: /^(-?(180(\.0+)?|((1[0-7][0-9]|[1-9]?[0-9])(\.\d+)?)))$/,
        message: "请输入正确的方向角度值 -180 ～ 180",
        trigger: "blur",
      },
    ],
    x: [newRule(true, "请输入节点x坐标", "blur")],
    y: [newRule(true, "请输入节点y坐标", "blur")],
    seriesId: [newRule(true, "请选择选择系列", "change")],
    modelsId: [newRule(true, "请选择选择型号", "change")],
    priorityNode: [
      {
        pattern: /^[0-9]\d*$/,
        message: "请输入正确停靠点优先级",
        trigger: "change",
        required: true
      }
    ],
  };

  get formData() {
    return this.#formData;
  }
  get formRules() {
    return this.#formRules;
  }
  get formOption() {
    return this.#formOption;
  }
  public getFormOption(optionParams: params) {
    // const dictionaryStore = useDictionaryStore();
    // const agvIdsOptions = dictionaryStore.agvDeiceLists.map((item: any) => {
    //   return {
    //     value: item.agvId,
    //     label: item.deviceName,
    //   };
    // });

    // const p1 = dictionaryStore.getlistNodeMap(optionParams.mapId, true, 10).then((res) => {
    //   const preNodeIdOptions = res.map((item: any) => {
    //     return {
    //       value: item.nodeId,
    //       label: `${item.node_name_en}(${item.node_name_cn})`,
    //     };
    //   });
    //   this.#formOption.formItems.filter((item) => item.field === "preNodeId")[0].options = preNodeIdOptions;
    // });
    // this.#formOption.formItems.filter((item) => item.field === "agvIds")[0].options = agvIdsOptions;
    // this.#formOption.formItems.filter((item) => item.field === "seriesId")[0].options = dictionaryStore.seriesAndModelsList;
    // return Promise.all([p1]);
  }
}
export class EdgeFormData {
  #formData: any = {
    id: "",
    edgeId: -1,
    mapId: -1,
    name: "",
    startNodeId: "",
    endNodeId: "",
    edgeType: -1,
    lineMode: -1,
    lengths: 0,
    sourceX: 0,
    sourceY: 0,
    targetX: 0,
    targetY: 0,
    pathGroupIds: [],
    speedGroupIds: [],
    capacity: null,
    released: ''
  };

  #formOption: FormOption = {
    formItems: [
      {
        field: "edgeName",
        prop: "edgeName",
        type: "input",
        label: "边ID",
        disabled: true,
        placeholder: "请输入边ID",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "edgeType",
        prop: "edgeType",
        type: "select",
        label: "边类型",
        options: edgeTypeList,
        placeholder: "请选择边类型",
        colSpan: 24,
      },
      {
        field: "lineMode",
        prop: "lineMode",
        type: "select",
        options: lineModeList,
        label: "边属性",
        placeholder: "请选择边属性",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "startNodeId",
        prop: "startNodeId",
        type: "input",
        label: "起始节点",
        disabled: true,
        placeholder: "请输入起始节点",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "endNodeId",
        prop: "endNodeId",
        type: "input",
        disabled: true,
        label: "结束节点",
        placeholder: "请输入结束节点",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "sourceX",
        prop: "sourceX",
        disabled: true,
        type: "input",
        label: "起点节点x(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "sourceY",
        prop: "sourceY",
        type: "input",
        disabled: true,
        label: "起点节点y(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "targetX",
        prop: "targetX",
        disabled: true,
        type: "input",
        label: "终点节点x(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "targetY",
        prop: "targetY",
        type: "input",
        disabled: true,
        label: "终点节点y(mm)",
        colSpan: 24,
        maxlength: 10,
      },
      {
        field: "lengths",
        prop: "lengths",
        type: "input",
        label: "边的长度",
        disabled: true,
        placeholder: "请输入边的长度",
        colSpan: 24,
        maxlength: 10,
      },
      // {
      //   field: "pathGroupIds",
      //   prop: "pathGroupIds",
      //   type: "select",
      //   options: [],
      //   label: "所属路径组",
      //   multiple: true,
      //   placeholder: "请选择所属路径组",
      //   colSpan: 24,
      //   maxlength: 10,
      // },
      // {
      //   field: "speedGroupIds",
      //   prop: "speedGroupIds",
      //   type: "select",
      //   options: [],
      //   label: "所属速度组",
      //   multiple: true,
      //   placeholder: "请选择所属速度组",
      //   colSpan: 24,
      //   maxlength: 10,
      // },
      // {
      //   field: "capacity",
      //   prop: "capacity",
      //   type: "select",
      //   options: [
      //     {
      //       value: 1,
      //       label: "仅倒车行驶",
      //     },
      //   ],
      //   label: "所属路径能力",
      //   placeholder: "请选择所属路径能力",
      //   colSpan: 24,
      //   maxlength: 10,
      // },
      // {
      //   field: "release",
      //   prop: "release",
      //   label: "状态",
      //   isHidden: true,
      //   slotName: "release",
      //   placeholder: "",
      //   colSpan: 24,
      //   maxlength: 10,
      // }
    ],
    labelWidth: "120px", //标签的长度
  };

  #formRules = {
    id: [newRule(true, "请输入边ID", "blur")],
    name: [newRule(true, "请输入边的名字", "blur")],
    startNodeId: [newRule(true, "请输入起始节点", "blur")],
    endNodeId: [newRule(true, "请输入结束节点", "blur")],
    edgeType: [newRule(true, "请选择边类型", "change")],
    lineMode: [newRule(true, "请选择边线条", "change")],
    length: [newRule(true, "请输入边的长度", "blur")],
  };
  get formData() {
    return this.#formData;
  }
  get formRules() {
    return this.#formRules;
  }
  get formOption() {
    return this.#formOption;
  }
  public getFormOption(optionParams: params) {
    // 获取路径组列表
    // const p1 = getPathGroup(optionParams.mapId).then((res: any) => {
    //   const pathGroupIds = this.#formOption.formItems.find((item) => item.field === "pathGroupIds");
    //   const speedGroupIds = this.#formOption.formItems.find((item) => item.field === "speedGroupIds");
    //   const groupInfos = res.pathGroup.groupInfos.map((item: any) => {
    //     return {
    //       value: item.id,
    //       label: item.groupName,
    //     };
    //   });
    //   const speedGroupInfos = res.pathGroup.speedGroupInfos.map((item: any) => {
    //     return {
    //       value: item.id,
    //       label: item.groupName,
    //     };
    //   });
    //   pathGroupIds?.options && (pathGroupIds.options = groupInfos);
    //   speedGroupIds?.options && (speedGroupIds.options = speedGroupInfos);
    // });
    // return Promise.all([p1]);
  }
}
